using Light;
using UnityEngine;
using Weapons.Components.ComponentData;
using Weapons.Components.ComponentData.AttackData;

namespace Weapons.Components
{
    public class PoiseDamage : WeaponComponent<PoiseDamageData, AttackPoiseDamage>
    {
        private ActionHitBox hitBox;

        protected override void Start()
        {
            base.Start();

            hitBox = GetComponent<ActionHitBox>();

            hitBox.OnDetectedCollider2D += HandleDetectCollider2D;
        }

        protected override void OnDestroy()
        {
            base.OnDestroy();

            hitBox.OnDetectedCollider2D -= HandleDetectCollider2D;
        }

        private void HandleDetectCollider2D(Collider2D[] colliders)
        {
            foreach (var item in colliders)
                if (item.TryGetComponent(out IPoiseDamageable poisDamageable))
                    poisDamageable.DamagePoise(currentAttackData.Amount);
        }
    }
}